package com.szpx.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.szpx.entity.LJK.LJKCoach;
import com.szpx.mapper.LJKCoachMapper;
import com.szpx.service.LJKCoachService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;


@Service
public class LJKCoachServiceImpl  implements LJKCoachService {

    @Resource
    private LJKCoachMapper ljkCoachMapper;
    @Override
    public LJKCoach getCoachById(Long id) {
        return ljkCoachMapper.selectById(id);
    }

    @Override
    public List<LJKCoach> getAllCoaches() {
        return ljkCoachMapper.selectAll();
    }

    @Override
    public PageInfo<LJKCoach> getCoachesByPage(int pageNum, int pageSize, LJKCoach ljkCoach) {
        // 使用分页插件实现分页查询 mybatis
        // 这里可以使用PageHelper等分页插件来实现
        // 例如：PageHelper.startPage(pageNum, pageSize);
        PageHelper.startPage(pageNum, pageSize);
        List<LJKCoach> ljkCoaches = ljkCoachMapper.selectByCon(ljkCoach);
        PageInfo<LJKCoach> pageInfo = new PageInfo<>(ljkCoaches);
        return pageInfo; // 示例中省略具体实现
    }

    @Override
    public boolean addCoach(LJKCoach coach) {
        return ljkCoachMapper.insert(coach) > 0;
    }

    @Override
    public boolean updateCoach(LJKCoach coach) {
        return false;
    }

    @Override
    public boolean deleteCoach(Long id) {
        return ljkCoachMapper.deleteById(id) > 0;
    }

    @Override
    public LJKCoach getCoachByPhone(String phone) {
        return ljkCoachMapper.selectByPhone(phone);
    }

    @Override
    public int batchAddCoaches(List<LJKCoach> coaches) {
        for (LJKCoach coach : coaches) {
            ljkCoachMapper.insert(coach);
        }
        return coaches.size();
    }
}
